package com.yuandengta.yomall.auth.service.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.yuandengta.common.utils.R;
import com.yuandengta.yomall.auth.feign.MemberFeignService;
import com.yuandengta.yomall.auth.service.RegisterService;
import com.yuandengta.yomall.auth.vo.UserRegisterVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户注册服务 {@link RegisterServiceImpl}
 */

@Slf4j
@Service
public class RegisterServiceImpl implements RegisterService {

    @Autowired
    MemberFeignService memberFeignService;

    /**
     * 会员注册
     * 放回来空，为了重定向url 登录
     *
     * @param registerVO
     */
    @Override
    public Map<String, String> reg(UserRegisterVO registerVO) {
        R r = memberFeignService.register(registerVO);
        if (r.getCode() != 0) {
            Map<String, String> errors = new HashMap<>();
            errors.put("msg", r.getData("msg", new TypeReference<String>() {
            }));
            return errors;
        }
        return null;
    }

    @Override
    public Integer checkUser(String username) {
        R r = memberFeignService.checkUser(username);
        return r.getCode();
    }

    @Override
    public Integer checkMobile(String mobile) {
        R r = memberFeignService.checkMobile(mobile);
        return r.getCode();
    }
}
